package com.c1202m.gui;

import java.awt.Image;

public class CustomMessageDialog extends javax.swing.JDialog {

    public static final int OK = 1;
    public static final int CANCEL = 0;
    public static final int MESSAGE = 2;
    public static final int CONFIRM = 3;
    public static final int DONE = 4;
    public static int STATUS = 0;

    /** Creates new form CustomMessageDialog */
    public CustomMessageDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Image icon = getToolkit().getImage(getClass().getResource("/images/volume.png"));
        setIconImage(icon);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnOK = new javax.swing.JButton();
        btnMessage = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        lbImage = new javax.swing.JLabel();
        txtMessage = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnOK.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        btnOK.setText("OK");
        btnOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKActionPerformed(evt);
            }
        });
        jPanel1.add(btnOK, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 80, -1, -1));

        btnMessage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ok.png"))); // NOI18N
        btnMessage.setText("OK");
        btnMessage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMessageActionPerformed(evt);
            }
        });
        jPanel1.add(btnMessage, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 80, -1, -1));

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/no.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setMargin(new java.awt.Insets(2, 5, 2, 5));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });
        jPanel1.add(btnCancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 80, -1, -1));

        lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/error.png"))); // NOI18N
        jPanel1.add(lbImage, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 60, 60));

        txtMessage.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        txtMessage.setForeground(new java.awt.Color(240, 0, 0));
        txtMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        txtMessage.setText("Display Message Here");
        txtMessage.setAutoscrolls(true);
        txtMessage.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.add(txtMessage, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 0, 200, 80));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        STATUS = CANCEL;
        dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
        // TODO add your handling code here:
        STATUS = OK;
        dispose();
    }//GEN-LAST:event_btnOKActionPerformed

    private void btnMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMessageActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnMessageActionPerformed

    public CustomMessageDialog(java.awt.Frame parent, boolean modal, String title, String confirm_message, int type) {
        super(parent, modal);
        initComponents();
        Image icon = getToolkit().getImage(getClass().getResource("/images/volume.png"));
        setIconImage(icon);
        txtMessage.setText(confirm_message);
        setTitle(title);
        STATUS = 0;

        if (type == MESSAGE) {
            btnOK.setVisible(false);
            btnCancel.setVisible(false);
            btnMessage.setVisible(true);
        } else if (type == CONFIRM) {
            lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/question.png")));
            btnOK.setVisible(true);
            btnCancel.setVisible(true);
            btnMessage.setVisible(false);
        } else if (type == DONE) {
            lbImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/done.png")));
            btnOK.setVisible(false);
            btnCancel.setVisible(false);
            btnMessage.setVisible(true);
        }

        setLocationRelativeTo(this);
        setVisible(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnMessage;
    private javax.swing.JButton btnOK;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbImage;
    private javax.swing.JLabel txtMessage;
    // End of variables declaration//GEN-END:variables
}
